﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;

namespace SocialMediaIntegrationPack
{
    public static class StringExtensions
    {
        /// <summary>
        /// Check if string contains format sequense
        /// </summary>
        public static bool IsFormat(this String value)
        {
            var formatRegex = new Regex("\\{\\d\\}");
            return formatRegex.IsMatch(value);
        }        
    }

    public static class QueriableExtensions
    {
        /// <summary>
        /// This method applys all expression to queriable collection
        /// </summary>
        public static IQueryable<T> WhereAll<T>(this IQueryable<T> queryable, IEnumerable<Expression<Func<T, bool>>> filters)
        {
            return filters.Aggregate(queryable, (current, filter) => current.Where(filter));
        }
    }
}